package br.empresa.sistema.web.controller;

import java.io.Serializable;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.TransactionPropagationType;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.faces.FacesMessages;

import br.empresa.sistema.dominio.Customer;
import br.empresa.sistema.service.CustomerService;

@Name("agendaControle")
public class AgendaController implements Serializable {
	
	private static final long serialVersionUID = 2687034918418350505L;

	@In(value="#{customerService}")
	private CustomerService customerFacade;
	
	@In
	private FacesMessages facesMessages;

	@In(value="#{customer}", scope=ScopeType.CONVERSATION) 
	@Out(scope=ScopeType.CONVERSATION)
	private Customer customer;
	
	@DataModel
	List<Customer> customers;
	
	@Begin
	public void novo() {
		//customer = new Customer();
	}
	
	public void proximo() {
	}
	
	@End
	@Transactional(TransactionPropagationType.SUPPORTS)
	public void registrar() {
		customerFacade.save(getCustomer());
		facesMessages.add("Saved!");
	}
	
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@Transactional(TransactionPropagationType.SUPPORTS)
	public List<Customer> getCustomers() {
		return customerFacade.retrieveAll();
	}

}